package com.dmcliver.expensemanager.session;

import com.dmcliver.expensemanager.entity.*;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("expenseHome")
public class ExpenseHome extends EntityHome<Expense> {

	@In(create = true)
	AccountuserHome accountuserHome;

	public void setExpenseExpensename(String id) {
		setId(id);
	}

	public String getExpenseExpensename() {
		return (String) getId();
	}

	@Override
	protected Expense createInstance() {
		Expense expense = new Expense();
		return expense;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Accountuser accountuser = accountuserHome.getDefinedInstance();
		if (accountuser != null) {
			getInstance().setAccountuser(accountuser);
		}
	}

	public boolean isWired() {
		if (getInstance().getAccountuser() == null)
			return false;
		return true;
	}

	public Expense getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

}
